#include "mainwindow.h"
#include "networker.h"
#include "ui_mainwindow.h"

#include <QDir>
#include <QFile>
#include <QJsonParseError>
#include <QSsl>
#include <QSslKey>
#include <QSslSocket>
#include <QStandardPaths>
#include <QTextCodec>
#include <QVariantMap>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    qDebug() << "支持OpenSSL: " << QSslSocket::supportsSsl();

    NetWorker* worker1 = NetWorker::instance();
    NetWorker* worker2 = NetWorker::instance();
    QNetworkReply *repl1 = worker1->get("https://kyfw.12306.cn/otn/index/init");
    QNetworkReply *repl2 = worker2->get("station_name");
    QNetworkReply *repl3 = worker2->get("station_qss");



//    qDebug()<<"start ";
//    QNetworkRequest mRequest;
//    QSslConfiguration config;
//    config.setPeerVerifyMode(QSslSocket::VerifyNone);
//    config.setProtocol(QSsl::TlsV1_2);
//    mRequest.setSslConfiguration(config);
//    mRequest.setUrl(QString("https://kyfw.12306.cn/otn/index/init"));
//    mRequest.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);

////    mRequest.setRawHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko");
////    mRequest.setRawHeader("Accept-Encoding", "gzip, deflate");
////    mRequest.setRawHeader("Accept-Language", "zh-Hans-CN,zh-Hans;q=0.8,en-US;q=0.5,en;q=0.3");
////    mRequest.setRawHeader("Accept", "*/*");
////    QNetworkReply *repl = worker->openGet(mRequest);
//    QNetworkAccessManager* pManager = new QNetworkAccessManager(this);
//    QNetworkReply *repl = pManager->get(mRequest);
//    QString result = repl->readAll();
//    qDebug()<<result;


////    QJsonParseError error;
////    QJsonDocument jsonDocument = QJsonDocument::fromJson(result.toLatin1(), &error);
////    qDebug()<<"start";
////    if (error.error == QJsonParseError::NoError) {
////        qDebug()<<" no error";
////        if (!(jsonDocument.isNull() || jsonDocument.isEmpty()) && jsonDocument.isObject()) {
////            qDebug()<<"is Object";
////            QVariantMap data = jsonDocument.toVariant().toMap();
////            qDebug()<<data[QLatin1String("debug")].toString();
////        }
////    }else{

////        qDebug()<<error.error;
////        qDebug()<<error.errorString();
////    }
    qDebug()<<"end ";
}

MainWindow::~MainWindow()
{
    delete ui;
}
